
package net.sshiffon.logging;

import javax.swing.JTextArea;
import org.apache.log4j.AppenderSkeleton;
import org.apache.log4j.spi.LoggingEvent;

/**
 *
 * @author amir
 */
public class JTextAreaAppender extends AppenderSkeleton {
    private JTextArea component;

    public JTextAreaAppender(JTextArea component)
    {
        this.component = component;
    }

    @Override
    protected void append(LoggingEvent event) {

        component.append(String.format("\n%5s [%s] %s",  event.getLevel(), event.getLoggerName() , event.getRenderedMessage() ));
        component.setCaretPosition(component.getDocument().getLength());

    }

    public void close() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public boolean requiresLayout() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

}
